package atag.runtime.ln.nodeAttributes;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * Defines a static double attribute.
 * 
 */
public class DoubleAttribute extends NodeAttribute {

	/**
	 * Creates a new instance of this attribute.
	 */
	public DoubleAttribute() {
	}

	/**
	 * Creates a new instance of this attribute.
	 * 
	 * @param key the name of the attribute.
	 * @param value the value associated.
	 */
	public DoubleAttribute(String key, double value) {

		this.key = key;
		this.value = new Double(value);
	}

	public String toString() {

		return "DoubleAttribute key = " + key + ", value = " + value;
	}
    public DataOutput serialize(DataOutput dg) throws IOException {

        dg.writeByte(DOUBLE_ATTR_TYPE);
        super.serialize(dg);
        dg.writeUTF(key);
        dg.writeDouble(((Double)this.value).doubleValue());
        return dg;
    }

     public static NodeAttribute deserialize(DataInput dg) throws IOException
     {
         String key = dg.readUTF();
         double value = dg.readDouble();
         DoubleAttribute da = new DoubleAttribute(key,value);
         return da;
     }
}
